/*
 * Click nbfs://nbhost/SystemFileSystem/Templates/Licenses/license-default.txt to change this license
 * Click nbfs://nbhost/SystemFileSystem/Templates/Classes/Class.java to edit this template
 */
package com.excesys.exsecs.controller;

import com.excesys.exsecs.config.MqttConfig;
import com.excesys.exsecs.common.core.util.R;
import com.excesys.exsecs.common.security.annotation.Inner;
import com.excesys.exsecs.dto.InvokeDTO;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.*;

import java.util.HashMap;
import java.util.Map;

/**
 * @author XuYangbo
 */
@Slf4j
@RestController
@RequestMapping("/v1/provide")
public class MqttProvideController {

	@Autowired
	private MqttConfig.MqttProducer mqttProducer;

	@Inner(value = false)
	@PostMapping(value = "/device/syncdata")
	public R<?> addOwner(@RequestBody InvokeDTO dto) {
		if (StringUtils.isEmpty(dto.getParams())) {
			return R.failed("发送参数不能为空");
		}

		mqttProducer.sendToMqtt(dto.getTopic(), dto.getParams());
		log.info("发送Mqtt成功,topic" + dto.getTopic() + ",data" + dto.getParams());
		return R.ok();
	}

}
